package torque.generated;


import java.math.BigDecimal;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.ObjectUtils;
import org.apache.torque.TorqueException;
import org.apache.torque.map.TableMap;
import org.apache.torque.om.BaseObject;
import org.apache.torque.om.ComboKey;
import org.apache.torque.om.DateKey;
import org.apache.torque.om.NumberKey;
import org.apache.torque.om.ObjectKey;
import org.apache.torque.om.SimpleKey;
import org.apache.torque.om.StringKey;
import org.apache.torque.om.Persistent;
import org.apache.torque.util.Criteria;
import org.apache.torque.util.Transaction;





/**
 * Objets
 *
 * This class was autogenerated by Torque on:
 *
 * [Tue Mar 24 08:44:00 CET 2009]
 *
 * You should not use this class directly.  It should not even be
 * extended all references should be to Objet
 */
public abstract class BaseObjet extends BaseObject
{
    /** Serial version */
    private static final long serialVersionUID = 1237880640559L;

    /** The Peer class */
    private static final ObjetPeer peer =
        new ObjetPeer();


    /** The value for the id field */
    private int id;

    /** The value for the type field */
    private String type;


    /**
     * Get the Id
     *
     * @return int
     */
    public int getId()
    {
        return id;
    }


    /**
     * Set the value of Id
     *
     * @param v new value
     */
    public void setId(int v) throws TorqueException
    {

        if (this.id != v)
        {
            this.id = v;
            setModified(true);
        }



        // update associated Cell
        if (collCells != null)
        {
            for (int i = 0; i < collCells.size(); i++)
            {
                ((Cell) collCells.get(i))
                        .setIdObjet(v);
            }
        }

        // update associated Arme
        if (collArmes != null)
        {
            for (int i = 0; i < collArmes.size(); i++)
            {
                ((Arme) collArmes.get(i))
                        .setIdObjet(v);
            }
        }

        // update associated Potion
        if (collPotions != null)
        {
            for (int i = 0; i < collPotions.size(); i++)
            {
                ((Potion) collPotions.get(i))
                        .setIdObjet(v);
            }
        }

        // update associated Sort
        if (collSorts != null)
        {
            for (int i = 0; i < collSorts.size(); i++)
            {
                ((Sort) collSorts.get(i))
                        .setIdObjet(v);
            }
        }

        // update associated Sad
        if (collSads != null)
        {
            for (int i = 0; i < collSads.size(); i++)
            {
                ((Sad) collSads.get(i))
                        .setIdObjet(v);
            }
        }
    }

    /**
     * Get the Type
     *
     * @return String
     */
    public String getType()
    {
        return type;
    }


    /**
     * Set the value of Type
     *
     * @param v new value
     */
    public void setType(String v) 
    {

        if (!ObjectUtils.equals(this.type, v))
        {
            this.type = v;
            setModified(true);
        }


    }

       


    /**
     * Collection to store aggregation of collCells
     */
    protected List collCells;

    /**
     * Temporary storage of collCells to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initCells()
    {
        if (collCells == null)
        {
            collCells = new ArrayList();
        }
    }


    /**
     * Method called to associate a Cell object to this object
     * through the Cell foreign key attribute
     *
     * @param l Cell
     * @throws TorqueException
     */
    public void addCell(Cell l) throws TorqueException
    {
        getCells().add(l);
        l.setObjet((Objet) this);
    }

    /**
     * Method called to associate a Cell object to this object
     * through the Cell foreign key attribute using connection.
     *
     * @param l Cell
     * @throws TorqueException
     */
    public void addCell(Cell l, Connection con) throws TorqueException
    {
        getCells(con).add(l);
        l.setObjet((Objet) this);
    }

    /**
     * The criteria used to select the current contents of collCells
     */
    private Criteria lastCellsCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getCells(new Criteria())
     *
     * @return the collection of associated objects
     * @throws TorqueException
     */
    public List getCells()
        throws TorqueException
    {
        if (collCells == null)
        {
            collCells = getCells(new Criteria(10));
        }
        return collCells;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Objet has previously
     * been saved, it will retrieve related Cells from storage.
     * If this Objet is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getCells(Criteria criteria) throws TorqueException
    {
        if (collCells == null)
        {
            if (isNew())
            {
               collCells = new ArrayList();
            }
            else
            {
                criteria.add(CellPeer.ID_OBJET, getId() );
                collCells = CellPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                criteria.add(CellPeer.ID_OBJET, getId());
                if (!lastCellsCriteria.equals(criteria))
                {
                    collCells = CellPeer.doSelect(criteria);
                }
            }
        }
        lastCellsCriteria = criteria;

        return collCells;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getCells(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getCells(Connection con) throws TorqueException
    {
        if (collCells == null)
        {
            collCells = getCells(new Criteria(10), con);
        }
        return collCells;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Objet has previously
     * been saved, it will retrieve related Cells from storage.
     * If this Objet is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getCells(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collCells == null)
        {
            if (isNew())
            {
               collCells = new ArrayList();
            }
            else
            {
                 criteria.add(CellPeer.ID_OBJET, getId());
                 collCells = CellPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                 criteria.add(CellPeer.ID_OBJET, getId());
                 if (!lastCellsCriteria.equals(criteria))
                 {
                     collCells = CellPeer.doSelect(criteria, con);
                 }
             }
         }
         lastCellsCriteria = criteria;

         return collCells;
     }











    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Objet is new, it will return
     * an empty collection; or if this Objet has previously
     * been saved, it will retrieve related Cells from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Objet.
     */
    protected List getCellsJoinObjet(Criteria criteria)
        throws TorqueException
    {
        if (collCells == null)
        {
            if (isNew())
            {
               collCells = new ArrayList();
            }
            else
            {
                criteria.add(CellPeer.ID_OBJET, getId());
                collCells = CellPeer.doSelectJoinObjet(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            criteria.add(CellPeer.ID_OBJET, getId());
            if (!lastCellsCriteria.equals(criteria))
            {
                collCells = CellPeer.doSelectJoinObjet(criteria);
            }
        }
        lastCellsCriteria = criteria;

        return collCells;
    }





    /**
     * Collection to store aggregation of collArmes
     */
    protected List collArmes;

    /**
     * Temporary storage of collArmes to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initArmes()
    {
        if (collArmes == null)
        {
            collArmes = new ArrayList();
        }
    }


    /**
     * Method called to associate a Arme object to this object
     * through the Arme foreign key attribute
     *
     * @param l Arme
     * @throws TorqueException
     */
    public void addArme(Arme l) throws TorqueException
    {
        getArmes().add(l);
        l.setObjet((Objet) this);
    }

    /**
     * Method called to associate a Arme object to this object
     * through the Arme foreign key attribute using connection.
     *
     * @param l Arme
     * @throws TorqueException
     */
    public void addArme(Arme l, Connection con) throws TorqueException
    {
        getArmes(con).add(l);
        l.setObjet((Objet) this);
    }

    /**
     * The criteria used to select the current contents of collArmes
     */
    private Criteria lastArmesCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getArmes(new Criteria())
     *
     * @return the collection of associated objects
     * @throws TorqueException
     */
    public List getArmes()
        throws TorqueException
    {
        if (collArmes == null)
        {
            collArmes = getArmes(new Criteria(10));
        }
        return collArmes;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Objet has previously
     * been saved, it will retrieve related Armes from storage.
     * If this Objet is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getArmes(Criteria criteria) throws TorqueException
    {
        if (collArmes == null)
        {
            if (isNew())
            {
               collArmes = new ArrayList();
            }
            else
            {
                criteria.add(ArmePeer.ID_OBJET, getId() );
                collArmes = ArmePeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                criteria.add(ArmePeer.ID_OBJET, getId());
                if (!lastArmesCriteria.equals(criteria))
                {
                    collArmes = ArmePeer.doSelect(criteria);
                }
            }
        }
        lastArmesCriteria = criteria;

        return collArmes;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getArmes(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getArmes(Connection con) throws TorqueException
    {
        if (collArmes == null)
        {
            collArmes = getArmes(new Criteria(10), con);
        }
        return collArmes;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Objet has previously
     * been saved, it will retrieve related Armes from storage.
     * If this Objet is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getArmes(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collArmes == null)
        {
            if (isNew())
            {
               collArmes = new ArrayList();
            }
            else
            {
                 criteria.add(ArmePeer.ID_OBJET, getId());
                 collArmes = ArmePeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                 criteria.add(ArmePeer.ID_OBJET, getId());
                 if (!lastArmesCriteria.equals(criteria))
                 {
                     collArmes = ArmePeer.doSelect(criteria, con);
                 }
             }
         }
         lastArmesCriteria = criteria;

         return collArmes;
     }











    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Objet is new, it will return
     * an empty collection; or if this Objet has previously
     * been saved, it will retrieve related Armes from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Objet.
     */
    protected List getArmesJoinObjet(Criteria criteria)
        throws TorqueException
    {
        if (collArmes == null)
        {
            if (isNew())
            {
               collArmes = new ArrayList();
            }
            else
            {
                criteria.add(ArmePeer.ID_OBJET, getId());
                collArmes = ArmePeer.doSelectJoinObjet(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            criteria.add(ArmePeer.ID_OBJET, getId());
            if (!lastArmesCriteria.equals(criteria))
            {
                collArmes = ArmePeer.doSelectJoinObjet(criteria);
            }
        }
        lastArmesCriteria = criteria;

        return collArmes;
    }





    /**
     * Collection to store aggregation of collPotions
     */
    protected List collPotions;

    /**
     * Temporary storage of collPotions to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initPotions()
    {
        if (collPotions == null)
        {
            collPotions = new ArrayList();
        }
    }


    /**
     * Method called to associate a Potion object to this object
     * through the Potion foreign key attribute
     *
     * @param l Potion
     * @throws TorqueException
     */
    public void addPotion(Potion l) throws TorqueException
    {
        getPotions().add(l);
        l.setObjet((Objet) this);
    }

    /**
     * Method called to associate a Potion object to this object
     * through the Potion foreign key attribute using connection.
     *
     * @param l Potion
     * @throws TorqueException
     */
    public void addPotion(Potion l, Connection con) throws TorqueException
    {
        getPotions(con).add(l);
        l.setObjet((Objet) this);
    }

    /**
     * The criteria used to select the current contents of collPotions
     */
    private Criteria lastPotionsCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getPotions(new Criteria())
     *
     * @return the collection of associated objects
     * @throws TorqueException
     */
    public List getPotions()
        throws TorqueException
    {
        if (collPotions == null)
        {
            collPotions = getPotions(new Criteria(10));
        }
        return collPotions;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Objet has previously
     * been saved, it will retrieve related Potions from storage.
     * If this Objet is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getPotions(Criteria criteria) throws TorqueException
    {
        if (collPotions == null)
        {
            if (isNew())
            {
               collPotions = new ArrayList();
            }
            else
            {
                criteria.add(PotionPeer.ID_OBJET, getId() );
                collPotions = PotionPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                criteria.add(PotionPeer.ID_OBJET, getId());
                if (!lastPotionsCriteria.equals(criteria))
                {
                    collPotions = PotionPeer.doSelect(criteria);
                }
            }
        }
        lastPotionsCriteria = criteria;

        return collPotions;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getPotions(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getPotions(Connection con) throws TorqueException
    {
        if (collPotions == null)
        {
            collPotions = getPotions(new Criteria(10), con);
        }
        return collPotions;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Objet has previously
     * been saved, it will retrieve related Potions from storage.
     * If this Objet is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getPotions(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collPotions == null)
        {
            if (isNew())
            {
               collPotions = new ArrayList();
            }
            else
            {
                 criteria.add(PotionPeer.ID_OBJET, getId());
                 collPotions = PotionPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                 criteria.add(PotionPeer.ID_OBJET, getId());
                 if (!lastPotionsCriteria.equals(criteria))
                 {
                     collPotions = PotionPeer.doSelect(criteria, con);
                 }
             }
         }
         lastPotionsCriteria = criteria;

         return collPotions;
     }











    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Objet is new, it will return
     * an empty collection; or if this Objet has previously
     * been saved, it will retrieve related Potions from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Objet.
     */
    protected List getPotionsJoinObjet(Criteria criteria)
        throws TorqueException
    {
        if (collPotions == null)
        {
            if (isNew())
            {
               collPotions = new ArrayList();
            }
            else
            {
                criteria.add(PotionPeer.ID_OBJET, getId());
                collPotions = PotionPeer.doSelectJoinObjet(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            criteria.add(PotionPeer.ID_OBJET, getId());
            if (!lastPotionsCriteria.equals(criteria))
            {
                collPotions = PotionPeer.doSelectJoinObjet(criteria);
            }
        }
        lastPotionsCriteria = criteria;

        return collPotions;
    }





    /**
     * Collection to store aggregation of collSorts
     */
    protected List collSorts;

    /**
     * Temporary storage of collSorts to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initSorts()
    {
        if (collSorts == null)
        {
            collSorts = new ArrayList();
        }
    }


    /**
     * Method called to associate a Sort object to this object
     * through the Sort foreign key attribute
     *
     * @param l Sort
     * @throws TorqueException
     */
    public void addSort(Sort l) throws TorqueException
    {
        getSorts().add(l);
        l.setObjet((Objet) this);
    }

    /**
     * Method called to associate a Sort object to this object
     * through the Sort foreign key attribute using connection.
     *
     * @param l Sort
     * @throws TorqueException
     */
    public void addSort(Sort l, Connection con) throws TorqueException
    {
        getSorts(con).add(l);
        l.setObjet((Objet) this);
    }

    /**
     * The criteria used to select the current contents of collSorts
     */
    private Criteria lastSortsCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getSorts(new Criteria())
     *
     * @return the collection of associated objects
     * @throws TorqueException
     */
    public List getSorts()
        throws TorqueException
    {
        if (collSorts == null)
        {
            collSorts = getSorts(new Criteria(10));
        }
        return collSorts;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Objet has previously
     * been saved, it will retrieve related Sorts from storage.
     * If this Objet is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getSorts(Criteria criteria) throws TorqueException
    {
        if (collSorts == null)
        {
            if (isNew())
            {
               collSorts = new ArrayList();
            }
            else
            {
                criteria.add(SortPeer.ID_OBJET, getId() );
                collSorts = SortPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                criteria.add(SortPeer.ID_OBJET, getId());
                if (!lastSortsCriteria.equals(criteria))
                {
                    collSorts = SortPeer.doSelect(criteria);
                }
            }
        }
        lastSortsCriteria = criteria;

        return collSorts;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getSorts(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getSorts(Connection con) throws TorqueException
    {
        if (collSorts == null)
        {
            collSorts = getSorts(new Criteria(10), con);
        }
        return collSorts;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Objet has previously
     * been saved, it will retrieve related Sorts from storage.
     * If this Objet is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getSorts(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collSorts == null)
        {
            if (isNew())
            {
               collSorts = new ArrayList();
            }
            else
            {
                 criteria.add(SortPeer.ID_OBJET, getId());
                 collSorts = SortPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                 criteria.add(SortPeer.ID_OBJET, getId());
                 if (!lastSortsCriteria.equals(criteria))
                 {
                     collSorts = SortPeer.doSelect(criteria, con);
                 }
             }
         }
         lastSortsCriteria = criteria;

         return collSorts;
     }











    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Objet is new, it will return
     * an empty collection; or if this Objet has previously
     * been saved, it will retrieve related Sorts from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Objet.
     */
    protected List getSortsJoinObjet(Criteria criteria)
        throws TorqueException
    {
        if (collSorts == null)
        {
            if (isNew())
            {
               collSorts = new ArrayList();
            }
            else
            {
                criteria.add(SortPeer.ID_OBJET, getId());
                collSorts = SortPeer.doSelectJoinObjet(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            criteria.add(SortPeer.ID_OBJET, getId());
            if (!lastSortsCriteria.equals(criteria))
            {
                collSorts = SortPeer.doSelectJoinObjet(criteria);
            }
        }
        lastSortsCriteria = criteria;

        return collSorts;
    }





    /**
     * Collection to store aggregation of collSads
     */
    protected List collSads;

    /**
     * Temporary storage of collSads to save a possible db hit in
     * the event objects are add to the collection, but the
     * complete collection is never requested.
     */
    protected void initSads()
    {
        if (collSads == null)
        {
            collSads = new ArrayList();
        }
    }


    /**
     * Method called to associate a Sad object to this object
     * through the Sad foreign key attribute
     *
     * @param l Sad
     * @throws TorqueException
     */
    public void addSad(Sad l) throws TorqueException
    {
        getSads().add(l);
        l.setObjet((Objet) this);
    }

    /**
     * Method called to associate a Sad object to this object
     * through the Sad foreign key attribute using connection.
     *
     * @param l Sad
     * @throws TorqueException
     */
    public void addSad(Sad l, Connection con) throws TorqueException
    {
        getSads(con).add(l);
        l.setObjet((Objet) this);
    }

    /**
     * The criteria used to select the current contents of collSads
     */
    private Criteria lastSadsCriteria = null;

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getSads(new Criteria())
     *
     * @return the collection of associated objects
     * @throws TorqueException
     */
    public List getSads()
        throws TorqueException
    {
        if (collSads == null)
        {
            collSads = getSads(new Criteria(10));
        }
        return collSads;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Objet has previously
     * been saved, it will retrieve related Sads from storage.
     * If this Objet is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     *
     * @throws TorqueException
     */
    public List getSads(Criteria criteria) throws TorqueException
    {
        if (collSads == null)
        {
            if (isNew())
            {
               collSads = new ArrayList();
            }
            else
            {
                criteria.add(SadPeer.ID_OBJET, getId() );
                collSads = SadPeer.doSelect(criteria);
            }
        }
        else
        {
            // criteria has no effect for a new object
            if (!isNew())
            {
                // the following code is to determine if a new query is
                // called for.  If the criteria is the same as the last
                // one, just return the collection.
                criteria.add(SadPeer.ID_OBJET, getId());
                if (!lastSadsCriteria.equals(criteria))
                {
                    collSads = SadPeer.doSelect(criteria);
                }
            }
        }
        lastSadsCriteria = criteria;

        return collSads;
    }

    /**
     * If this collection has already been initialized, returns
     * the collection. Otherwise returns the results of
     * getSads(new Criteria(),Connection)
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getSads(Connection con) throws TorqueException
    {
        if (collSads == null)
        {
            collSads = getSads(new Criteria(10), con);
        }
        return collSads;
    }

    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Objet has previously
     * been saved, it will retrieve related Sads from storage.
     * If this Objet is new, it will return
     * an empty collection or the current collection, the criteria
     * is ignored on a new object.
     * This method takes in the Connection also as input so that
     * referenced objects can also be obtained using a Connection
     * that is taken as input
     */
    public List getSads(Criteria criteria, Connection con)
            throws TorqueException
    {
        if (collSads == null)
        {
            if (isNew())
            {
               collSads = new ArrayList();
            }
            else
            {
                 criteria.add(SadPeer.ID_OBJET, getId());
                 collSads = SadPeer.doSelect(criteria, con);
             }
         }
         else
         {
             // criteria has no effect for a new object
             if (!isNew())
             {
                 // the following code is to determine if a new query is
                 // called for.  If the criteria is the same as the last
                 // one, just return the collection.
                 criteria.add(SadPeer.ID_OBJET, getId());
                 if (!lastSadsCriteria.equals(criteria))
                 {
                     collSads = SadPeer.doSelect(criteria, con);
                 }
             }
         }
         lastSadsCriteria = criteria;

         return collSads;
     }











    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Objet is new, it will return
     * an empty collection; or if this Objet has previously
     * been saved, it will retrieve related Sads from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Objet.
     */
    protected List getSadsJoinTroll(Criteria criteria)
        throws TorqueException
    {
        if (collSads == null)
        {
            if (isNew())
            {
               collSads = new ArrayList();
            }
            else
            {
                criteria.add(SadPeer.ID_OBJET, getId());
                collSads = SadPeer.doSelectJoinTroll(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            criteria.add(SadPeer.ID_OBJET, getId());
            if (!lastSadsCriteria.equals(criteria))
            {
                collSads = SadPeer.doSelectJoinTroll(criteria);
            }
        }
        lastSadsCriteria = criteria;

        return collSads;
    }









    /**
     * If this collection has already been initialized with
     * an identical criteria, it returns the collection.
     * Otherwise if this Objet is new, it will return
     * an empty collection; or if this Objet has previously
     * been saved, it will retrieve related Sads from storage.
     *
     * This method is protected by default in order to keep the public
     * api reasonable.  You can provide public methods for those you
     * actually need in Objet.
     */
    protected List getSadsJoinObjet(Criteria criteria)
        throws TorqueException
    {
        if (collSads == null)
        {
            if (isNew())
            {
               collSads = new ArrayList();
            }
            else
            {
                criteria.add(SadPeer.ID_OBJET, getId());
                collSads = SadPeer.doSelectJoinObjet(criteria);
            }
        }
        else
        {
            // the following code is to determine if a new query is
            // called for.  If the criteria is the same as the last
            // one, just return the collection.
            criteria.add(SadPeer.ID_OBJET, getId());
            if (!lastSadsCriteria.equals(criteria))
            {
                collSads = SadPeer.doSelectJoinObjet(criteria);
            }
        }
        lastSadsCriteria = criteria;

        return collSads;
    }



        
    private static List fieldNames = null;

    /**
     * Generate a list of field names.
     *
     * @return a list of field names
     */
    public static synchronized List getFieldNames()
    {
        if (fieldNames == null)
        {
            fieldNames = new ArrayList();
            fieldNames.add("Id");
            fieldNames.add("Type");
            fieldNames = Collections.unmodifiableList(fieldNames);
        }
        return fieldNames;
    }

    /**
     * Retrieves a field from the object by field (Java) name passed in as a String.
     *
     * @param name field name
     * @return value
     */
    public Object getByName(String name)
    {
        if (name.equals("Id"))
        {
            return new Integer(getId());
        }
        if (name.equals("Type"))
        {
            return getType();
        }
        return null;
    }

    /**
     * Set a field in the object by field (Java) name.
     *
     * @param name field name
     * @param value field value
     * @return True if value was set, false if not (invalid name / protected field).
     * @throws IllegalArgumentException if object type of value does not match field object type.
     * @throws TorqueException If a problem occurs with the set[Field] method.
     */
    public boolean setByName(String name, Object value )
        throws TorqueException, IllegalArgumentException
    {
        if (name.equals("Id"))
        {
            if (value == null || ! (Integer.class.isInstance(value)))
            {
                throw new IllegalArgumentException("setByName: value parameter was null or not an Integer object.");
            }
            setId(((Integer) value).intValue());
            return true;
        }
        if (name.equals("Type"))
        {
            // Object fields can be null
            if (value != null && ! String.class.isInstance(value))
            {
                throw new IllegalArgumentException("Invalid type of object specified for value in setByName");
            }
            setType((String) value);
            return true;
        }
        return false;
    }

    /**
     * Retrieves a field from the object by name passed in
     * as a String.  The String must be one of the static
     * Strings defined in this Class' Peer.
     *
     * @param name peer name
     * @return value
     */
    public Object getByPeerName(String name)
    {
        if (name.equals(ObjetPeer.ID))
        {
            return new Integer(getId());
        }
        if (name.equals(ObjetPeer.TYPE))
        {
            return getType();
        }
        return null;
    }

    /**
     * Set field values by Peer Field Name
     *
     * @param name field name
     * @param value field value
     * @return True if value was set, false if not (invalid name / protected field).
     * @throws IllegalArgumentException if object type of value does not match field object type.
     * @throws TorqueException If a problem occurs with the set[Field] method.
     */
    public boolean setByPeerName(String name, Object value)
        throws TorqueException, IllegalArgumentException
    {
      if (ObjetPeer.ID.equals(name))
        {
            return setByName("Id", value);
        }
      if (ObjetPeer.TYPE.equals(name))
        {
            return setByName("Type", value);
        }
        return false;
    }

    /**
     * Retrieves a field from the object by Position as specified
     * in the xml schema.  Zero-based.
     *
     * @param pos position in xml schema
     * @return value
     */
    public Object getByPosition(int pos)
    {
        if (pos == 0)
        {
            return new Integer(getId());
        }
        if (pos == 1)
        {
            return getType();
        }
        return null;
    }

    /**
     * Set field values by its position (zero based) in the XML schema.
     *
     * @param position The field position
     * @param value field value
     * @return True if value was set, false if not (invalid position / protected field).
     * @throws IllegalArgumentException if object type of value does not match field object type.
     * @throws TorqueException If a problem occurs with the set[Field] method.
     */
    public boolean setByPosition(int position, Object value)
        throws TorqueException, IllegalArgumentException
    {
    if (position == 0)
        {
            return setByName("Id", value);
        }
    if (position == 1)
        {
            return setByName("Type", value);
        }
        return false;
    }
     
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     *
     * @throws Exception
     */
    public void save() throws Exception
    {
        save(ObjetPeer.DATABASE_NAME);
    }

    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.
     * Note: this code is here because the method body is
     * auto-generated conditionally and therefore needs to be
     * in this file instead of in the super class, BaseObject.
     *
     * @param dbName
     * @throws TorqueException
     */
    public void save(String dbName) throws TorqueException
    {
        Connection con = null;
        try
        {
            con = Transaction.begin(dbName);
            save(con);
            Transaction.commit(con);
        }
        catch(TorqueException e)
        {
            Transaction.safeRollback(con);
            throw e;
        }
    }

    /** flag to prevent endless save loop, if this object is referenced
        by another object which falls in this transaction. */
    private boolean alreadyInSave = false;
    /**
     * Stores the object in the database.  If the object is new,
     * it inserts it; otherwise an update is performed.  This method
     * is meant to be used as part of a transaction, otherwise use
     * the save() method and the connection details will be handled
     * internally
     *
     * @param con
     * @throws TorqueException
     */
    public void save(Connection con) throws TorqueException
    {
        if (!alreadyInSave)
        {
            alreadyInSave = true;



            // If this object has been modified, then save it to the database.
            if (isModified())
            {
                if (isNew())
                {
                    ObjetPeer.doInsert((Objet) this, con);
                    setNew(false);
                }
                else
                {
                    ObjetPeer.doUpdate((Objet) this, con);
                }
            }


            if (collCells != null)
            {
                for (int i = 0; i < collCells.size(); i++)
                {
                    ((Cell) collCells.get(i)).save(con);
                }
            }

            if (collArmes != null)
            {
                for (int i = 0; i < collArmes.size(); i++)
                {
                    ((Arme) collArmes.get(i)).save(con);
                }
            }

            if (collPotions != null)
            {
                for (int i = 0; i < collPotions.size(); i++)
                {
                    ((Potion) collPotions.get(i)).save(con);
                }
            }

            if (collSorts != null)
            {
                for (int i = 0; i < collSorts.size(); i++)
                {
                    ((Sort) collSorts.get(i)).save(con);
                }
            }

            if (collSads != null)
            {
                for (int i = 0; i < collSads.size(); i++)
                {
                    ((Sad) collSads.get(i)).save(con);
                }
            }
            alreadyInSave = false;
        }
    }


    /**
     * Set the PrimaryKey using ObjectKey.
     *
     * @param key id ObjectKey
     */
    public void setPrimaryKey(ObjectKey key)
        throws TorqueException
    {
        setId(((NumberKey) key).intValue());
    }

    /**
     * Set the PrimaryKey using a String.
     *
     * @param key
     */
    public void setPrimaryKey(String key) throws TorqueException
    {
        setId(Integer.parseInt(key));
    }


    /**
     * returns an id that differentiates this object from others
     * of its class.
     */
    public ObjectKey getPrimaryKey()
    {
        return SimpleKey.keyFor(getId());
    }
 

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
     * It then fills all the association collections and sets the
     * related objects to isNew=true.
     */
    public Objet copy() throws TorqueException
    {
        return copy(true);
    }

    /**
     * Makes a copy of this object using connection.
     * It creates a new object filling in the simple attributes.
     * It then fills all the association collections and sets the
     * related objects to isNew=true.
     *
     * @param con the database connection to read associated objects.
     */
    public Objet copy(Connection con) throws TorqueException
    {
        return copy(true, con);
    }

    /**
     * Makes a copy of this object.
     * It creates a new object filling in the simple attributes.
     * If the parameter deepcopy is true, it then fills all the
     * association collections and sets the related objects to
     * isNew=true.
     *
     * @param deepcopy whether to copy the associated objects.
     */
    public Objet copy(boolean deepcopy) throws TorqueException
    {
        return copyInto(new Objet(), deepcopy);
    }

    /**
     * Makes a copy of this object using connection.
     * It creates a new object filling in the simple attributes.
     * If the parameter deepcopy is true, it then fills all the
     * association collections and sets the related objects to
     * isNew=true.
     *
     * @param deepcopy whether to copy the associated objects.
     * @param con the database connection to read associated objects.
     */
    public Objet copy(boolean deepcopy, Connection con) throws TorqueException
    {
        return copyInto(new Objet(), deepcopy, con);
    }
  
    /**
     * Fills the copyObj with the contents of this object.
     * The associated objects are also copied and treated as new objects.
     *
     * @param copyObj the object to fill.
     */
    protected Objet copyInto(Objet copyObj) throws TorqueException
    {
        return copyInto(copyObj, true);
    }

  
    /**
     * Fills the copyObj with the contents of this object using connection.
     * The associated objects are also copied and treated as new objects.
     *
     * @param copyObj the object to fill.
     * @param con the database connection to read associated objects.
     */
    protected Objet copyInto(Objet copyObj, Connection con) throws TorqueException
    {
        return copyInto(copyObj, true, con);
    }
  
    /**
     * Fills the copyObj with the contents of this object.
     * If deepcopy is true, The associated objects are also copied
     * and treated as new objects.
     *
     * @param copyObj the object to fill.
     * @param deepcopy whether the associated objects should be copied.
     */
    protected Objet copyInto(Objet copyObj, boolean deepcopy) throws TorqueException
    {
        copyObj.setId(id);
        copyObj.setType(type);

        copyObj.setId( 0);

        if (deepcopy)
        {


        List vCells = getCells();
        if (vCells != null)
        {
            for (int i = 0; i < vCells.size(); i++)
            {
                Cell obj = (Cell) vCells.get(i);
                copyObj.addCell(obj.copy());
            }
        }
        else
        {
            copyObj.collCells = null;
        }


        List vArmes = getArmes();
        if (vArmes != null)
        {
            for (int i = 0; i < vArmes.size(); i++)
            {
                Arme obj = (Arme) vArmes.get(i);
                copyObj.addArme(obj.copy());
            }
        }
        else
        {
            copyObj.collArmes = null;
        }


        List vPotions = getPotions();
        if (vPotions != null)
        {
            for (int i = 0; i < vPotions.size(); i++)
            {
                Potion obj = (Potion) vPotions.get(i);
                copyObj.addPotion(obj.copy());
            }
        }
        else
        {
            copyObj.collPotions = null;
        }


        List vSorts = getSorts();
        if (vSorts != null)
        {
            for (int i = 0; i < vSorts.size(); i++)
            {
                Sort obj = (Sort) vSorts.get(i);
                copyObj.addSort(obj.copy());
            }
        }
        else
        {
            copyObj.collSorts = null;
        }


        List vSads = getSads();
        if (vSads != null)
        {
            for (int i = 0; i < vSads.size(); i++)
            {
                Sad obj = (Sad) vSads.get(i);
                copyObj.addSad(obj.copy());
            }
        }
        else
        {
            copyObj.collSads = null;
        }
        }
        return copyObj;
    }
        
    
    /**
     * Fills the copyObj with the contents of this object using connection.
     * If deepcopy is true, The associated objects are also copied
     * and treated as new objects.
     *
     * @param copyObj the object to fill.
     * @param deepcopy whether the associated objects should be copied.
     * @param con the database connection to read associated objects.
     */
    protected Objet copyInto(Objet copyObj, boolean deepcopy, Connection con) throws TorqueException
    {
        copyObj.setId(id);
        copyObj.setType(type);

        copyObj.setId( 0);

        if (deepcopy)
        {


        List vCells = getCells(con);
        if (vCells != null)
        {
            for (int i = 0; i < vCells.size(); i++)
            {
                Cell obj = (Cell) vCells.get(i);
                copyObj.addCell(obj.copy(con), con);
            }
        }
        else
        {
            copyObj.collCells = null;
        }


        List vArmes = getArmes(con);
        if (vArmes != null)
        {
            for (int i = 0; i < vArmes.size(); i++)
            {
                Arme obj = (Arme) vArmes.get(i);
                copyObj.addArme(obj.copy(con), con);
            }
        }
        else
        {
            copyObj.collArmes = null;
        }


        List vPotions = getPotions(con);
        if (vPotions != null)
        {
            for (int i = 0; i < vPotions.size(); i++)
            {
                Potion obj = (Potion) vPotions.get(i);
                copyObj.addPotion(obj.copy(con), con);
            }
        }
        else
        {
            copyObj.collPotions = null;
        }


        List vSorts = getSorts(con);
        if (vSorts != null)
        {
            for (int i = 0; i < vSorts.size(); i++)
            {
                Sort obj = (Sort) vSorts.get(i);
                copyObj.addSort(obj.copy(con), con);
            }
        }
        else
        {
            copyObj.collSorts = null;
        }


        List vSads = getSads(con);
        if (vSads != null)
        {
            for (int i = 0; i < vSads.size(); i++)
            {
                Sad obj = (Sad) vSads.get(i);
                copyObj.addSad(obj.copy(con), con);
            }
        }
        else
        {
            copyObj.collSads = null;
        }
        }
        return copyObj;
    }
    
    

    /**
     * returns a peer instance associated with this om.  Since Peer classes
     * are not to have any instance attributes, this method returns the
     * same instance for all member of this class. The method could therefore
     * be static, but this would prevent one from overriding the behavior.
     */
    public ObjetPeer getPeer()
    {
        return peer;
    }

    /**
     * Retrieves the TableMap object related to this Table data without
     * compiler warnings of using getPeer().getTableMap().
     *
     * @return The associated TableMap object.
     */
    public TableMap getTableMap() throws TorqueException
    {
        return ObjetPeer.getTableMap();
    }


    public String toString()
    {
        StringBuffer str = new StringBuffer();
        str.append("Objet:\n");
        str.append("Id = ")
           .append(getId())
           .append("\n");
        str.append("Type = ")
           .append(getType())
           .append("\n");
        return(str.toString());
    }
}
